package org.mtmi.ui.links;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.mtmi.ui.GraphicUtil;
import org.mtmi.ui.controls.IVisualControl;

/**
 * Provides connection point in control's rectangle outline, 
 * as if given point is linked to center of control's bounds.
 */
public class ChopBoxConnectionProvider implements IConnectionOutlinePointProvider
{
	private IVisualControl control;
	private Rectangle      rectangle;
	
	public ChopBoxConnectionProvider( IVisualControl c ) {
		control = c;
	}
	
	/** use rectangle instead of control's bounds */
	public ChopBoxConnectionProvider( Rectangle r ) {
		rectangle = r;
	}
	
	@Override
	public Point getOutlinePoint( int x, int y ) 
	{
		if( control!=null ) {
			Point l = control.getLocation();
			Point s = control.getSize();
			Point p = GraphicUtil.pointToCenterOutlinePoint( l, s, x, y );
			return p;
		} else {
			Point p = GraphicUtil.pointToCenterOutlinePoint( rectangle, x, y );
			return p;
		}
	}

}
